﻿using Microsoft.Extensions.Caching.Memory;
using OA.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OA.BLL
{
    public class CMailbox : CBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        /// <param name="type">1:收件箱 0：发件箱</param>
        public static void Map(List<Mailbox> list,int type, IMemoryCache _cache)
        {
            if(list==null|| list.Count == 0)
            {
                return;
            }
            CacheHelper cacheHelper = new CacheHelper(_cache);           
            List<Employee> listEmployee = cacheHelper.GetEmployees();
            foreach (Mailbox item in list)
            {
                if(type==1)
                {
                    Employee infoEmployee = listEmployee.Where(m => m.EmpID == item.FromEmpID).FirstOrDefault();
                    if (infoEmployee != null)
                    {
                        item.Pic = infoEmployee.Pic;
                    }
                }
                else
                {
                    Employee infoEmployee = listEmployee.Where(m => m.EmpID == item.ToEmpID).FirstOrDefault();
                    if (infoEmployee != null)
                    {
                        item.Pic = infoEmployee.Pic;
                    }
                }                
            }
        }
    }
}
